package com.qixin.part.controller;


import com.qixin.part.bean.PtDic;
import com.qixin.part.bean.ZtreeBean;
import com.qixin.part.service.PtDicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-09-28
 */
@Controller
@RequestMapping("/ptDic")
public class PtDicController {
    private static final Logger logger = LoggerFactory.getLogger(PtDicController.class);
    @Autowired
    PtDicService ptDicService;

    @Value("${cacheName}")
    String cacheName = "";


    //跳转页面
    @RequestMapping("/main.html")
    public String main( ) {
        return "system/dic";
    }


    /**
     * 测试缓存 缓存

     */
/*
    @RequestMapping("/testCach")
    @ResponseBody
    public boolean testCach(){
        logger.info(ptDicService.testEhcahe("dicData").toString());
        return true;

    }
*/

    @RequestMapping("/insertDic")
    @ResponseBody
    public boolean index(PtDic ptDic){
        ptDic.setCreateTime(new Date().getTime());
        return ptDicService.MyInsert(ptDic);
    }
    //查询出所有ztree需要的树数据
    @RequestMapping("/selectDic")
    @ResponseBody

    public List<ZtreeBean> selectDic(PtDic ptDic){
        List<ZtreeBean> list= ptDicService.selectDic();
        return list;
    }
    //查询树的所有信息   根据id
    @RequestMapping("/selectDicById")
    @ResponseBody
    public PtDic selectDicById(PtDic ptDic, MultipartFile file){
        PtDic ptDicPojo = ptDicService.selectDicById(ptDic.getId());
        return ptDicPojo;
    }
    //根据id删除节点 如果有子节点 则连带删除
    @RequestMapping("/deletById")
    @ResponseBody

    public String deletById(PtDic ptDic) {
        if (ptDicService.deletAllDicById(ptDic)){
            return "删除成功";
        }else{
            return  "删除失败";
        }
    }
   /*public  boolean deletById(PtDic sysDic){
       return
    }*/


    //根据code查询字典表子节点
    @RequestMapping("/findDataByDicCode")
    @ResponseBody
    public List<PtDic> findDataByDicCode(String code) {
        return   ptDicService.findDataByDicCode(code);
    }


}
